package com.example.administrator.printoutindemo.juese;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.ListView;

import com.dds.soap.SoapListener;
import com.dds.soap.SoapParams;
import com.example.administrator.printoutindemo.R;
import com.example.administrator.printoutindemo.adapter.ShenHeRenAdapter;
import com.example.administrator.printoutindemo.base.BaseActivity;
import com.example.administrator.printoutindemo.bean.ShenHeRenBean;
import com.example.administrator.printoutindemo.http.HttpManager;
import com.example.administrator.printoutindemo.http.SPUtil;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jess.arms.base.BaseConstants;

import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by noc on 2018/10/24.
 */

public class ShenHeRenActivity extends BaseActivity {

    private ListView lv_list;
    private List<ShenHeRenBean> mlist;
    private ShenHeRenAdapter mAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.shrandckmdxmlist);
        lv_list = (ListView) findViewById(R.id.lv_list);
        mlist = new ArrayList<>();
        mAdapter = new ShenHeRenAdapter(ShenHeRenActivity.this, mlist);
        lv_list.setAdapter(mAdapter);
        getChecUser();
    }

    private void getChecUser() {


        String methodName = "GetChecUser";

        SoapParams params = new SoapParams();
        params.put("user_id", SPUtil.getString(ShenHeRenActivity.this, "iduser", ""));



        /**
         * 请求
         */
        soapUtil.callEntry(getUrl(), BaseConstants.NAME_SPACE, methodName, params, new SoapListener() {
            @Override
            public void onSuccess(int statusCode, SoapObject object) {

                String result = object.getProperty(methodName + "Result").toString();
                if (result != null && !result.equals("[]") && !result.equals("anyType{}") && !result.equals("Error") && !result.equals("-100")) {
                    Log.e("dayin=====", result);
                    List<ShenHeRenBean> shenHeRenBeen = new Gson().fromJson(result, new TypeToken<List<ShenHeRenBean>>() {
                    }.getType());
                    mAdapter.addAll(shenHeRenBeen);
                } else {

                }

            }

            @Override
            public void onFailure(int statusCode, String content, Throwable error) {
            }

            @Override
            public void onFailure(int statusCode, SoapFault fault) {
            }
        }, getAapiUserName(), getApiPwd());
    }

}
